package com.yl.auth.service.impl;

import com.yl.auth.model.entity.Quanxian;
import com.yl.auth.mapper.QuanxianMapper;
import com.yl.auth.model.vo.QuanxianVo;
import com.yl.auth.service.QuanxianService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ln
 * @since 2023-06-29
 */
@Service
public class QuanxianServiceImpl extends ServiceImpl<QuanxianMapper, Quanxian> implements QuanxianService {

    @Autowired
    private QuanxianMapper quanxianMapper;

    @Override
    public List<QuanxianVo> gitQuanXianList() {
        List<QuanxianVo> quanxianVoList = new ArrayList<>();

        //查询一级信息
        List<QuanxianVo> xianList = quanxianMapper.gitQuanXianList(1L);
        for (QuanxianVo q : xianList){
            quanxianVoList.add(q);
        }

        for (QuanxianVo quanxian : quanxianVoList){
            List<QuanxianVo> list = quanxianMapper.gitQuanXianList(quanxian.getId());
            quanxian.setChildren(list);
        }

        return quanxianVoList;
    }
}
